local extension = Package:new("YS__mondstadt")
extension.extensionName = "2333333"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
     ["YS__mondstadt"] = "○神-蒙德",
     ["YS"] = "○神",
}

local YS__dlk = General(extension, "YS__dlk", "Pyro", 4, 4, General.Male)
local YS__dlkwin = fk.CreateActiveSkill{ name = "YS__dlk_win_audio" }
YS__dlkwin.package = extension
Fk:addSkill(YS__dlkwin)
local YS__niyan = fk.CreateViewAsSkill{
  name = "YS__niyan",
  anim_type = "offensive",
  mute = true,
  enabled_at_play = function(self, player)
    local usedTimes = player:usedSkillTimes(self.name) + 1
    return player:getMark("YS__niyan_nullified-turn") == 0 and
      #player:getCardIds({ Player.Hand, Player.Equip }) >= usedTimes
  end,
  card_filter = function(self, to_select, selected)
    return
      #selected <= Self:usedSkillTimes(self.name) and
      Fk:getCardById(to_select).color == Card.Red and
      not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  view_as = function(self, cards)
      if #cards ~= Self:usedSkillTimes(self.name) + 1 then
        return nil
      end
    local card = Fk:cloneCard("fire__slash")
    card.skillName = self.name
    card:setMark("YS__niyan_discard", cards)
    return card
  end,
  before_use = function(self, player, useData)
    local room = player.room
    local cards = useData.card:getMark("YS__niyan_discard")
    if player:usedSkillTimes(self.name) == 1 then
      player:broadcastSkillInvoke(self.name, 1)
    elseif player:usedSkillTimes(self.name) == 2 then
      player:broadcastSkillInvoke(self.name, 2)
    elseif player:usedSkillTimes(self.name) == 3 then
      player:broadcastSkillInvoke(self.name, 3)
    end
    if cards and #cards > 0 then
      room:throwCard(cards, self.name, player, player)
    end
    room:addPlayerMark(player, "@YS__niyan-turn")
    if player:getMark("@YS__niyan-turn") == 3 then
      player:addSkillUseHistory(self.name, -3)
      --useData.additionalDamage = (useData.additionalDamage or 0) + 1
      room:setPlayerMark(player, "@YS__niyan-turn", 0)
    end
    useData.extraUse = true
  end
}
local YS__niyanBuff = fk.CreateTargetModSkill{
  name = "#YS__niyan-buff",
  residue_func = function(self, player, skill, scope, card)
    return (player:hasSkill(self) and card and table.contains(card.skillNames, YS__niyan.name)) and 999 or 0
  end,
}
local YS__niyanSlash = fk.CreateTriggerSkill{
  name = "#YS__niyanSlash",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local cardnum = player:getHandcardNum()
    local to = player.room:getPlayerById(data.to)
    local aims=#AimGroup:getAllTargets(data.tos)
      if target == player and data.card.trueName == "slash" and player:hasSkill(YS__niyan) then
        if event == fk.TargetSpecified and not to:isNude() and cardnum%2 == 1 then
          return aims==1 and not to.dead and to.hp > 0
        elseif event == fk.TargetSpecified and to.hp >= player.hp then
          return aims==1 and not to.dead and to.hp > 0
        else
          return false
      end
  end
end,
  on_cost = function(self, event, target, player, data)
    local cardnum = player:getHandcardNum()
    local to = player.room:getPlayerById(data.to)
    if event == fk.TargetSpecified and not to:isNude() and cardnum%2 == 1 and to.hp >= player.hp then
      if player.room:askForSkillInvoke(player, self.name, nil, "#YS__niyan-invoke3::"..data.to) then
        player.room:doIndicate(player.id, { to.id })
        return true
      end
    elseif event == fk.TargetSpecified and to.hp >= player.hp then
      if player.room:askForSkillInvoke(player, self.name, nil, "#YS__niyan-invoke2::"..data.to) then
        player.room:doIndicate(player.id, { to.id })
        return true
      end
    elseif event == fk.TargetSpecified and not to:isNude() and cardnum%2 == 1 then
      if player.room:askForSkillInvoke(player, self.name, nil, "#YS__niyan-invoke1::"..data.to) then
        player.room:doIndicate(player.id, { to.id })
        return true
      end
    end
end,
  on_use = function(self, event, target, player, data)
    local rand = math.random(1, 2)
    if rand == 1 then
      player:broadcastSkillInvoke("YS__niyan", 4)
    else
      player:broadcastSkillInvoke("YS__niyan", 5)
    end
    local room = player.room
    if event == fk.TargetSpecified then
      local to = room:getPlayerById(data.to)
      local cardnum = player:getHandcardNum()
      if not to:isNude() and cardnum%2 == 1 then
      local cards = room:askForCardsChosen(player, to, 1, 1, "he", self.name)
      to:addToPile(self.name, cards, false, self.name)
      end
      if to.hp >= player.hp then
        if #room.draw_pile > 0 then
          local cards2 = room:getCardsFromPileByRule(".|.|heart,diamond", 1)
          if #cards2 > 0 then
          room:obtainCard(player, cards2[1], false, fk.ReasonJustMove)
          end
        end
      end
    end
  end,


  refresh_events = {fk.DamageCaused},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.to:isKongcheng() and data.card and data.card.trueName == "slash" and
      not data.chain
    end,
  on_refresh = function(self, event, target, player, data)
    local rand = math.random(1, 2)
    if rand == 1 then
      player:broadcastSkillInvoke("YS__niyan", 4)
    else
      player:broadcastSkillInvoke("YS__niyan", 5)
    end
    data.damage = data.damage + 1
  end,
}
local YS__niyanSlash_delay = fk.CreateTriggerSkill{
  name = "#YS__niyanSlash_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("#YS__niyanSlash") > 0
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local dummy = Fk:cloneCard("zixing")
    dummy:addSubcards(player:getPile("#YS__niyanSlash"))
    local room = player.room
    room:obtainCard(player.id, dummy, false)
  end,
}

YS__niyan:addRelatedSkill(YS__niyanBuff)
YS__dlk:addSkill(YS__niyan)
YS__niyan:addRelatedSkill(YS__niyanSlash)
YS__niyan:addRelatedSkill(YS__niyanSlash_delay)
Fk:loadTranslationTable{
  ["YS__dlk"] = "迪卢克",
  ["YS__niyan"] = "逆炎",
  ["@YS__niyan-turn"] = "<font color='Red'>逆炎</font>",
  ["#YS__niyanSlash"] = "逆炎",
  ["YS__niyan_discard"] = "弃置红色牌",
  ["#YS__niyan-invoke1"] = "逆炎:将%dest的一张牌置于武将牌上",
  ["#YS__niyan-invoke2"] = "逆炎:此杀结算后，你可以获得一张红色牌",
  ["#YS__niyan-invoke3"] = "逆炎:将%dest的一张牌置于武将牌上,且此杀结算后，你可以获得一张红色牌",
  [":YS__niyan"] = "出牌阶段，你可以弃置X+1张红色牌视为使用一张无次数限制的火【杀】，当你本回合第三次使用此技能时，你重置此技能；" ..
  "当你使用【杀】指定一个目标后，若你的手牌数为奇数，你可以将其一张牌置于其武将牌上，当前回合结束后，其获得这些牌；" ..
  "若你的体力值不大于其，则此【杀】结算后，你可以从牌堆中获得一张随机红色牌;若其没有手牌，则此【杀】伤害+1（X为你本回合使用此技能的次数）。",
  ["$YS__niyan1"] = "呵",
  ["$YS__niyan2"] = "哈",
  ["$YS__niyan3"] = "哈！————",
  ["$YS__niyan4"] = "火焰——烧尽————",
  ["$YS__niyan5"] = "在此——宣判————",
  ["~YS__dlk"] = "败者…没有借口…",
  ["$YS__dlk_win_audio"] = "这场胜利，我拿下了。",
}

local YS__q = General(extension, "YS__q", "Anemo", 4, 4, General.Female)
local YS__qwin = fk.CreateActiveSkill{ name = "YS__q_win_audio" }
YS__qwin.package = extension
Fk:addSkill(YS__qwin)
local YS__fengya = fk.CreateTriggerSkill{
  name = "YS__fengya",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and #AimGroup:getAllTargets(data.tos) == 1 and
      not player.room:getPlayerById(AimGroup:getAllTargets(data.tos)[1]):isNude() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#YS__fengya-invoke::"..data.to) then
      player.room:doIndicate(player.id, {data.to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(AimGroup:getAllTargets(data.tos)[1])
    room:doIndicate(player.id, {to.id})
    local cards = room:askForCardsChosen(player, to, 1, 2, "he", self.name)
    room:throwCard(cards, self.name, to, player)
    room:addPlayerMark(to, "@YS__fengya-turn", 2)
  end,
}
local YS__fengya_delay = fk.CreateTriggerSkill{
  name = "#YS__fengya_delay",
  mute = true,
  events = {fk.TurnEnd, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      return player:getMark("@YS__fengya-turn") > 0
    else
      return false
    end
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local num = player:getMark("@YS__fengya-turn")
    if num < 3 then
      player:drawCards(num)
    else
      player:drawCards(2)
    end
  end,

  refresh_events = {fk.Damage},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.to:getMark("@YS__fengya-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(data.to, "@YS__fengya-turn", -data.damage)
    player.room:addPlayerMark(player, "@YS__fengya-turn", data.damage)
    local num = data.to:getMark("@YS__fengya-turn")
    if num == 0 then
      player.room:setPlayerMark(data.to, "@@YS__jifei", 1)
    end
    if player:getMark("@YS__fengya-turn") > 2 then
      player.room:setPlayerMark(player, "@YS__fengya-turn", 2)
    end
  end,
}
local YS__jifei = fk.CreateTriggerSkill{
  name = "#YS__jifei",
  events = {fk.EventPhaseStart},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player == target and player.phase == Player.Start and player:getMark("@@YS__jifei") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@YS__jifei", 0)
    player:skip(Player.Play)
    player:skip(Player.Discard)
  end,
}
local YS__fengyin = fk.CreateViewAsSkill{
  name = "YS__fengyin",
  pattern = "jink,nullification,peach",
  anim_type = "support",
  interaction = function(self)
    local names = {}
    for _, name in ipairs(self.pattern:split(",")) do
      local card = Fk:cloneCard(name)
      if ((Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        table.insertIfNeed(names, name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    if #cards == 0 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local num = #use.card.subcards
    local room = player.room
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player
    end), function(p)
      return p.id
    end)
    local targets = room:askForChoosePlayers(player, availableTargets, 1, num, "#YS__fengyin-invoke::", self.name, true)
    if targets then
      for _, targetId in ipairs(targets) do
        local ta = room:getPlayerById(targetId)
        room:recover({
          who = ta,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
        if not ta.dead and #ta:getCardIds("j") > 0 then
          ta:throwAllCards("j")
        end
      end
    end
    local to = room.current
      if not to:isNude() then
        room:doIndicate(player.id, to)
        local cards = room:askForCardsChosen(player, to, 0, num, "he", self.name)
        room:throwCard(cards, self.name, to, player)
      end
  end,
  enabled_at_play = function(self, player)
    return false
  end,
  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(self.name, Player.HistoryRound) == 0 and not player:isKongcheng() and player.phase == Player.NotActive
  end
}
YS__q:addSkill(YS__fengya)
YS__fengya:addRelatedSkill(YS__fengya_delay)
YS__fengya:addRelatedSkill(YS__jifei)
YS__q:addSkill(YS__fengyin)
Fk:loadTranslationTable{
  ["YS__q"] = "琴",
  ["YS__fengya"] = "风压",
  ["#YS__fengya-invoke"] = "风压:弃置%dest至多两张牌，令其获得两个风压标记。",
  ["#YS__fengyin-invoke"] = "你可以选择等量其他角色发动风引",
  ["@YS__fengya-turn"] = "<font color='#1AFD9C'>风压</font>",
  ["#YS__fengya_delay"] = "风压",
  ["YS__fengyin"] = "风引",
  ["@@YS__jifei"] = "<font color='#4EFEB3'>击飞</font>",
  ["#YS__jifei"] = "击飞",
  [":YS__fengya"] = "每回合限一次，当你使用【杀】指定唯一目标后，你可以弃置其至多两张牌，然后其获得两个“风压”；"..
  "有“风压”的角色受到伤害时，伤害来源获得其一个“风压”;当其失去所有“风压”时，其跳过下一个出牌阶段和弃牌阶段；"..
  "当前回合结束时，有“风压”的角色摸等同于“风压”的牌，然后清除所有“风压”。",
  [":YS__fengyin"] = "每轮限一次，你的回合外，你可以将任意张手牌当做一张【闪】/【桃】/【无懈可击】使用或打出，如此做，你回复一点体力然后你可以令至多X名其他角色各回复一点体力并弃置判定区里所有的牌；"..
  "然后你可以弃置当前回合角色至多X张牌。（X为你以此法使用的牌）",
  ["$YS__fengya1"] = "…哈！",
  ["$YS__fengya2"] = "…散！",
  ["$YS__fengya3"] = "一决胜负！",
  ["$YS__fengyin1"] = "风之神，请指引我们。",
  ["$YS__fengyin2"] = "以剑为誓！",
  ["$YS__fengyin3"] = "风，回应我吧。",
  ["$YS__q_win_audio"] = "我以此剑起誓，必将胜利献给你。",
  ["~YS__q"] = "蒙德…",
}



local YS__yl = General(extension, "YS__yl", "Cryo", 4, 4, General.Female)
local YS__ylwin = fk.CreateActiveSkill{ name = "YS__yl_win_audio" }
YS__ylwin.package = extension
Fk:addSkill(YS__ylwin)
local YS__bingchao = fk.CreateTriggerSkill{
  name = "YS__bingchao",
  anim_type = "defensive",
  events = {fk.DamageCaused},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and (data.card.type == Card.TypeTrick or data.card.type == Card.TypeBasic) and player.room:askForSkillInvoke(player, self.name, nil, "冰潮：令此伤害减一")
  end,
  on_use = function(self, event, target, player, data)
  player:broadcastSkillInvoke("YS__bingchao", math.random(1, 3))
  local room = player.room
  local to = data.to
  data.damage = data.damage - 1
  room:addPlayerMark(player, "@lengku", 1)
  if not to:isNude() then
    room:doIndicate(player.id, to)
    local cards = room:askForCardsChosen(player, to, 0, 1, "hej", self.name)
    room:throwCard(cards, self.name, to, player)
  end
  end,
  priority = 3,
}
local YS__ninglangB = fk.CreateTriggerSkill{
  name = "#YS__ninglangB",
  anim_type = "offensive",
  mute = true,
  events = {fk.TargetSpecified},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
      if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 then
          local aims=#AimGroup:getAllTargets(data.tos)
          return aims==1 and data.card.trueName == "slash" and player.phase ~= Player.NotActive and player.room:askForSkillInvoke(player, self.name, nil, "#YS__ninglangB-invoke::"..data.to)
      else
          return false
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    room:addPlayerMark(to, "@@guangjiang-turn", 1)
  end,
}
local YS__bingchaoB = fk.CreateTriggerSkill{
  name = "#YS__bingchaoB",
  anim_type = "defensive",
  mute = true,
  events = {fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and player.phase == Player.Play and data.to:getMark("@@guangjiang-turn") ~= 0
  end,
  on_use = function(self, event, target, player, data)
  local room = player.room
  room:addPlayerMark(player, "@lengku", 1)
  end,
}
local YS__bingchaoSlash = fk.CreateTriggerSkill{
  name = "#YS__bingchaoSlash",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.from == player.id
    and data.card.trueName == "slash" and not player.room:getPlayerById(data.to).dead and player:getMark("@lengku") > 0 and player.room:askForSkillInvoke(player, self.name, nil, "是否移去一个冷酷令此杀依然造成伤害。")
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@lengku", -1)
    return true
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("YS__bingchao", math.random(4, 6))
    local room = player.room
    return true
  end,
}
local YS__bingchao_trigger = fk.CreateTriggerSkill{
  name = "#YS__bingchao_trigger",
  mute = true,
  events = {fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and not data.chain and data.card and data.card.trueName == "slash" and player:getMark("@lengku") ~= 0 and player.room:askForSkillInvoke(player, self.name, nil, "是否移去一个冷酷令此杀造成的伤害+1。")
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@lengku", -1)
    return true
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("YS__bingchao", math.random(4, 6))
    data.damage = data.damage + 1
  end,
  priority = 2,
}
local YS__ninglang = fk.CreateTriggerSkill{
  name = "YS__ninglang",
  anim_type = "drawcard",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("@lengku") < 4 then
      player:broadcastSkillInvoke("YS__ninglang", 4)
      room:addPlayerMark(player, "@lengku", 1)
    else
      local num = player:getMark("@lengku")
      local availableTargets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return p:getMark("@@guangjiang-turn") ~= 0
      end), Util.IdMapper)
      if #availableTargets ~= 0 then
      player:broadcastSkillInvoke("YS__ninglang", math.random(1, 3))
      room:doIndicate(player.id, room:getPlayerById(availableTargets[1]))
      room:damage{
        from = player,
        to = room:getPlayerById(availableTargets[1]),
        damage = num,
        damageType = fk.NormalDamage,
        skillName = self.name,
      }
      room:setPlayerMark(player, "@lengku", 0)
      end
    end
  end,
}
YS__yl:addSkill(YS__bingchao)
YS__bingchao:addRelatedSkill(YS__bingchaoB)
YS__bingchao:addRelatedSkill(YS__bingchaoSlash)
YS__bingchao:addRelatedSkill(YS__bingchao_trigger)
YS__yl:addSkill(YS__ninglang)
YS__ninglang:addRelatedSkill(YS__ninglangB)
Fk:loadTranslationTable{
  ["YS__yl"] = "优菈",
  ["YS__bingchao"] = "冰潮",
  ["@lengku"] = "<font color='#80FFFF'>冷酷</font>",
  ["#YS__bingchaoSlash"] = "冰潮",
  ["#YS__bingchaoB"] = "冰潮",
  ["#YS__bingchao_trigger"] = "冰潮",
  ["YS__ninglang"] = "凝浪",
  ["#YS__ninglangB"] = "凝浪",
  ["@@guangjiang-turn"] = "<font color='#80FFFF'>光降</font>",
  ["#YS__ninglangB-invoke"] = "凝浪：你可以令%dest获得一个光降标记",
  [":YS__bingchao"] = "当你使用牌造成伤害时，你可以令此伤害-1，然后你可以弃置目标区域内一张牌并获得一个“冷酷”；①你使用【杀】造成伤害时，你可以移去一个“冷酷”令此【杀】伤害+1；②你使用的【杀】被【闪】抵消时，你可以移去一个“冷酷”令此【杀】仍然造成伤害。",
  [":YS__ninglang"] = "出牌阶段限一次，当你使用【杀】指定唯一目标后，你可以令其成为“光降目标”；你对“光降目标”造成伤害后，你获得一个“冷酷”。结束阶段，若你的“冷酷”小于4，你可以获得一个“冷酷”；若你的“冷酷”不小于4，则你可以移去所有“冷酷”，对“光降目标”造成等量伤害。",
  ["$YS__bingchao1"] = "结霜！",
  ["$YS__bingchao2"] = "求饶吧。",
  ["$YS__bingchao3"] = "粉化！",
  ["$YS__bingchao4"] = "破碎！",
  ["$YS__bingchao5"] = "以眼还眼！",
  ["$YS__bingchao6"] = "判决！",
  ["$YS__ninglang1"] = "坚冰，断绝深仇！",
  ["$YS__ninglang2"] = "以霜还怨！",
  ["$YS__ninglang3"] = "冰浪怒涛！",
  ["$YS__ninglang4"] = "可恶，这个仇我记下了！",
  ["$YS__yl_win_audio"] = "游击骑士，率先行动。",
  ["~YS__yl"] = "狼狈的收场…",
}



local YS__ab = General(extension, "YS__ab", "Pyro", 3, 3, General.Female)
local YS__abwin = fk.CreateActiveSkill{ name = "YS__ab_win_audio" }
YS__abwin.package = extension
Fk:addSkill(YS__abwin)
local ttbj_W = {{"ttbj", Card.Heart, 2},{"ttbj", Card.Heart, 4},{"ttbj", Card.Heart, 6},{"ttbj", Card.Heart, 8},{"ttbj", Card.Diamond, 3},{"ttbj", Card.Diamond, 5},{"ttbj", Card.Diamond, 7},{"ttbj", Card.Diamond, 9}}
local ttbj_A = {{"ttbjArmor", Card.Heart, 2},{"ttbjArmor", Card.Heart, 4},{"ttbjArmor", Card.Heart, 6},{"ttbjArmor", Card.Heart, 8},{"ttbjArmor", Card.Diamond, 3},{"ttbjArmor", Card.Diamond, 5},{"ttbjArmor", Card.Diamond, 7},{"ttbjArmor", Card.Diamond, 9}}
Fk:addPoxiMethod{
  name = "YS__baodanchoose",
  card_filter = function(to_select, selected, data)
    local name = Fk:getCardById(to_select).name
    return name == "ttbj" or name == "ttbjArmor"
  end,
  feasible = function(selected)
    return #selected == 1
  end,
  prompt = function ()
    return "爆弹：选择对方一张兔兔伯爵"
  end
}
local YS__baodan_active = fk.CreateViewAsSkill{
  name = "YS__baodan_active",
  pattern = "fire__slash,jink",
  mute = true,
  interaction = function()
    local names = {}
    local pat = Fk.currentResponsePattern
    if pat == nil and Self:canUse(Fk:cloneCard("fire__slash")) and table.find(Fk:currentRoom().alive_players, function(p)
      return (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "ttbj") or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name == "ttbjArmor") end) then
      table.insert(names, "fire__slash")
    else
      if Exppattern:Parse(pat):matchExp("fire__slash") and table.find(Fk:currentRoom().alive_players, function(p)
        return (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "ttbj") or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name == "ttbjArmor") end) then
          table.insert(names, "fire__slash")
      end
      if Exppattern:Parse(pat):matchExp("jink") and table.find(Fk:currentRoom().alive_players, function(p)
        return (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "ttbj") or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name == "ttbjArmor") end) then
          table.insert(names, "jink")
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  view_as = function(self, cards)
    if self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "ttbj") or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name == "ttbjArmor")
    end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#askttbj::", self.name, false, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        local target_e = to:getCardIds("e")
        local card = room:askForPoxi(player, "YS__baodanchoose", {
          { to.general, target_e },
        }, nil, true)
        player.room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
        if room:getCardOwner(card[1]) == player and room:getCardArea(card[1]) == Player.Hand then
          use.card:addSubcard(card[1])
          use.extraUse = false
          player:drawCards(2)
          if use.card.trueName == "jink" then
            player:broadcastSkillInvoke("YS__baodan_active", 4)
            room:notifySkillInvoked(player, "YS__baodan_active", "defensive")
          else
            player:broadcastSkillInvoke("YS__baodan_active", math.random(5,6))
            room:notifySkillInvoked(player, "YS__baodan_active", "offensive")
          end
          return
        end
      end
    end
    return ""
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and table.find(Fk:currentRoom().alive_players, function(p)
      return (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "ttbj") or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name == "ttbjArmor") end)
  end,
  enabled_at_response = function(self, player)
    local pat = Fk.currentResponsePattern
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and pat and table.find(Fk:currentRoom().alive_players, function(p)
      return ((Exppattern:Parse(pat):matchExp("fire__slash") or Exppattern:Parse(pat):matchExp("jink")) and (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "ttbj") or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name == "ttbjArmor"))
    end)
  end,
}
local YS__baodan = fk.CreateTriggerSkill{
  name = "#YS__baodan",
  anim_type = "support",
  mute = true,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local card1 = table.filter(U.prepareDeriveCards(room, ttbj_W, "YS__baodanW"), function (id)
      return room:getCardArea(id) == Card.Void
    end)
    local card2 = table.filter(U.prepareDeriveCards(room, ttbj_A, "YS__baodanA"), function (id)
      return room:getCardArea(id) == Card.Void
    end)
    return player:hasSkill(self) and #card1 ~= 0 and target == player and #card2 ~= 0 and table.find(room.alive_players, function(p) return p ~= player and ((p:hasEmptyEquipSlot(Card.SubtypeArmor) or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name ~= "ttbjArmor")) or (p:hasEmptyEquipSlot(Card.SubtypeWeapon) or (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name ~= "ttbj"))) end) and not player:isNude() 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local S = room:askForSkillInvoke(player, self.name, data, "#askbd::")
    if S then
      local choice = {}
      if table.find(room.alive_players, function(p) return  p ~= player and (p:hasEmptyEquipSlot(Card.SubtypeArmor) or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name ~= "ttbjArmor")) end) then
        table.insert(choice, "ArmorSlot")
      end
      if table.find(room.alive_players, function(p) return  p ~= player and (p:hasEmptyEquipSlot(Card.SubtypeWeapon) or (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name ~= "ttbj")) end) then
        table.insert(choice, "WeaponSlot")
      end
      local C = room:askForChoice(player, choice, self.name, "#askbdqy::", nil, {"ArmorSlot","WeaponSlot"})
      if C == "ArmorSlot" then
        local targets = table.filter(room.alive_players, function(p) return  p ~= player and (p:hasEmptyEquipSlot(Card.SubtypeArmor) or (p:getEquipment(Card.SubtypeArmor) and Fk:getCardById(p:getEquipment(Card.SubtypeArmor), true).name ~= "ttbjArmor")) end)
        local tos, cards = U.askForChooseCardsAndPlayers(room, player, 1, 1, table.map(targets, Util.IdMapper), 1, 1, ".","爆弹", false, false)
        room:throwCard(cards, self.name, player, player)
        local to = room:getPlayerById(tos[1])
        self.cost_data = {to, C}
        return true
      elseif C == "WeaponSlot" then
        local targets = table.filter(room.alive_players, function(p) return  p ~= player and (p:hasEmptyEquipSlot(Card.SubtypeWeapon) or (p:getEquipment(Card.SubtypeWeapon) and Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name ~= "ttbj")) end)
        local tos, cards = U.askForChooseCardsAndPlayers(room, player, 1, 1, table.map(targets, Util.IdMapper), 1, 1, ".","爆弹", false, false)
        room:throwCard(cards, self.name, player, player)
        local to = room:getPlayerById(tos[1])
        self.cost_data = {to, C}
        return true
      end
    else
      return false
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data[2] == "ArmorSlot" then
      local cards = table.filter(U.prepareDeriveCards(room, ttbj_A, "YS__baodanA"), function (id)
        return room:getCardArea(id) == Card.Void
      end)
      local get = table.random(cards)
      if get then
        room:setCardMark(Fk:getCardById(get), MarkEnum.DestructIntoDiscard, 1)
        U.moveCardIntoEquip(room, self.cost_data[1], get, self.name, true, player)
        player:broadcastSkillInvoke("YS__baodan_active", math.random(1,3))
        room:notifySkillInvoked(player, "YS__baodan_active", "control")
      end
    end
    if self.cost_data[2] == "WeaponSlot" then
      local cards = table.filter(U.prepareDeriveCards(room, ttbj_W, "YS__baodanW"), function (id)
        return room:getCardArea(id) == Card.Void
      end)
      local get = table.random(cards)
      if get then
        room:setCardMark(Fk:getCardById(get), MarkEnum.DestructIntoDiscard, 1)
        U.moveCardIntoEquip(room, self.cost_data[1], get, self.name, true, player)
        player:broadcastSkillInvoke("YS__baodan_active", math.random(1,3))
        room:notifySkillInvoked(player, "YS__baodan_active", "control")
      end
    end
  end,
}
local YS__jianyv = fk.CreateViewAsSkill{
  name = "YS__jianyv",
  pattern = "archery_attack",
  anim_type = "offensive",
  card_filter = function(self, to_select, selected)
    return false
  end,
  view_as = function(self, cards)
    local card = Fk:cloneCard(self.pattern)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:setPlayerMark(player, "@YS__jianyv", 4)
  end,
  enabled_at_play = function(self, player)
    return player.phase == Player.Play and player:getMark("@YS__jianyv") == 0
  end,
  enabled_at_response = function(self, player, cardResponsing)
    return false
  end,
}
local YS__jianyv_trig = fk.CreateTriggerSkill{
  name = "#YS__jianyv_trig",
  mute = true,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@YS__jianyv") > 0 and table.find(data, function(move) return move.to == player.id and move.toArea == Card.PlayerHand end)
  end,
  on_refresh = function(self, event, target, player, data)
    local num = player:getMark("@YS__jianyv")
    for _, move in ipairs(data) do
      if move.toArea == Card.PlayerHand and move.to == player.id and move.moveReason == fk.ReasonDraw then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DrawPile then
            num = num - 1
          end
        end
      end
      if num <= 0 then
        player.room:setPlayerMark(player, "@YS__jianyv", 0)
        return false
      end
    end
    player.room:setPlayerMark(player, "@YS__jianyv", num)
  end,
}
local YS__jianyv_delay = fk.CreateTriggerSkill{
  name = "#YS__jianyv_delay",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Play and data.card and table.contains(data.card.skillNames, "YS__jianyv")
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    data.damageType = fk.FireDamage
  end,
}
YS__ab:addSkill(YS__baodan_active)
YS__baodan_active:addRelatedSkill(YS__baodan)
YS__ab:addSkill(YS__jianyv)
YS__jianyv:addRelatedSkill(YS__jianyv_trig)
YS__jianyv:addRelatedSkill(YS__jianyv_delay)
Fk:loadTranslationTable{
  ["YS__ab"] = "安柏",
  ["#YS__baodan"] = "爆弹",
  ["#askbdqy"] = "选择一个区域置入兔兔伯爵",
  ["#askbd"] = "是否发动爆弹",
  ["#askttbj"] = "选择一名有兔兔伯爵的角色",
  ["YS__baodan_active"] = "爆弹",
  [":YS__baodan_active"] = "回合开始时，你可以弃置一张牌并选择一个区域，然后将一张【兔兔伯爵】置于一名其他角色的装备区里。每回合限一次，你可以将场上一张【兔兔伯爵】当火【杀】或【闪】使用或打出，如此做你摸两张牌。"..
  "<br/><font color='grey'>#\"<b>兔兔伯爵（武器）</b>\"：锁定技，攻击距离为0，当此牌离开你的装备区时，你受到一点无来源的火焰伤害"..
  "<br/><font color='grey'>#\"<b>兔兔伯爵（防具）</b>\"：锁定技，当你受到火焰伤害时，你弃置此牌；当此牌离开你的装备区时，你受到一点无来源的火焰伤害",
  ["YS__jianyv"] = "箭雨",
  [":YS__jianyv"] = "昂扬技，出牌阶段你可以视为使用一张【万箭齐发】，此【万箭齐发】造成的伤害视为火焰伤害。<u>激昂</u>：你摸4张牌。"..
  "<br/><font color='grey'>#\"<b>昂扬技</b>\"：昂扬技发动后，技能失效直到满足<b>激昂</b>条件。",
  ["@YS__jianyv"] = "<font color='#FF0000'>箭雨</font>",
  ["$YS__baodan_active1"] = "靠你咯。",
  ["$YS__baodan_active2"] = "兔兔伯爵，出击！",
  ["$YS__baodan_active3"] = "哼哼~哼哼哼~",
  ["$YS__baodan_active4"] = "跟得上我吗？",
  ["$YS__baodan_active5"] = "就是这种感觉！",
  ["$YS__baodan_active6"] = "侦察骑士登场！",
  ["$YS__jianyv1"] = "百发百中！",
  ["$YS__jianyv2"] = "箭如…雨下！",
  ["$YS__jianyv3"] = "你没有退路了！",
  ["$YS__ab_win_audio"] = "侦察骑士，发现目标！",
  ["~YS__ab"] = "训练…还不够…",
}

local YS__b_wd = General(extension, "YS__b_wd", "Anemo", 3, 3, General.Male)
local YS__b_wdwin = fk.CreateActiveSkill{ name = "YS__b_wd_win_audio" }
YS__b_wdwin.package = extension
Fk:addSkill(YS__b_wdwin)
local YS__gaotian = fk.CreateActiveSkill{
  name = "YS__gaotian",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(self.name) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    player:showCards(effect.cards)
    room:obtainCard(target, Fk:getCardById(effect.cards[1]), true, fk.ReasonGive, player.id)
    target:drawCards(1)
    local suitsRecorded = type(target:getMark("@YS__baofeng")) == "table" and target:getMark("@YS__baofeng") or {}
    table.insertIfNeed(suitsRecorded, Fk:getCardById(effect.cards[1]):getSuitString(true))
    room:setPlayerMark(target, "@YS__baofeng", suitsRecorded)
    room:handleAddLoseSkills(target, 'YS__baofeng', nil, true)
  end,
}
local YS__baofeng_del = fk.CreateTriggerSkill{
  name = "#YS__baofeng_del",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target:getMark("@YS__baofeng") == 0 and target:hasSkill("YS__baofeng")
  end,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(target, '-YS__baofeng', nil, true)
  end,
}
local YS__baofeng_skip = fk.CreateTriggerSkill{
  name = "#YS__baofeng_skip",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player == target and player.phase == Player.Start and player:getMark("@YS__baofeng") ~= 0 and player:hasSkill("YS__baofeng")
  end,
  on_use = function(self, event, target, player, data)
    player:skip(Player.Judge)
    player:skip(Player.Draw)
    player:drawCards(1)
  end,
}

local YS__baofeng = fk.CreateActiveSkill{
  name = "YS__baofeng",
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Frequent,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:getMark("@YS__baofeng") ~= 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local room = player.room
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
        return p ~= player and (p.chained or player:distanceTo(p) == 1)
      end), function(p)
        return p.id
      end)
      if #availableTargets == 0 then return false end
    for _, targetId in ipairs(availableTargets) do
      local to = room:getPlayerById(targetId)
      local suits = player:getMark("@YS__baofeng")
      to:setChainState(true)
      local cards = table.filter(to:getCardIds({Player.Equip}), function (id)
        return table.contains(suits, Fk:getCardById(id):getSuitString(true))
      end)
      local hand = to:getCardIds("h")
      for _, id in ipairs(hand) do
        if table.contains(suits, Fk:getCardById(id):getSuitString(true)) and not table.contains(cards, id) then
          table.insert(cards, id)
        end
      end
      local pd = to:getCardIds("j")
      for _, id in ipairs(pd) do
        if table.contains(suits, Fk:getCardById(id):getSuitString(true)) and not table.contains(cards, id) then
          table.insert(cards, id)
        end
      end
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
      end
    end
    room:setPlayerMark(player, "@YS__baofeng", 0)
end,
}
local YS__baofengBuff = fk.CreateDistanceSkill{
  name = "#YS__baofengBuff",
  mute = true,
  correct_func = function(self, from, to)
    if to:hasSkill("YS__baofeng") and to:getMark("@YS__baofeng") ~= 0 and type(to:getMark("@YS__baofeng")) == "table" then
      return #to:getMark("@YS__baofeng")
    end
  end,
}
local YS__baofeng_targetmod = fk.CreateTargetModSkill{
  name = "#YS__baofeng_targetmod",
  bypass_distances = function(self, player, skill, card, to)
    return player:getMark("@YS__baofeng") == 0 and player.phase ~= Player.NotActive and player:hasSkill("YS__baofeng")
  end,
}
Fk:loadTranslationTable{
  ["YS__b_wd"] = "温迪",
  ["YS__gaotian"] = "高天",
  [":YS__gaotian"] = "出牌阶段限一次，你可以交给一名角色一张手牌，令其获得此牌花色的“暴风”然后摸一张牌，有“暴风”的角色视为拥有技能〖暴风〗。",
  ["YS__baofeng"] = "暴风",
  ["@YS__baofeng"] = "<font color='#02F78E'>暴风</font>",
  [":YS__baofeng"] = "出牌阶段限一次，你可以弃置“暴风”并获得与其距离为1或处于横置状态的所有其他角色区域里所有与“暴风”花色相同的牌，然后你横置这些角色且你使用牌无距离限制直到回合结束。其他角色与你计算距离时+X；回合开始时，你摸一张牌并跳过判定和摸牌阶段。(X为“暴风”拥有的花色数)",
  ["#YS__baofeng_del"] = "暴风",
  ["#YS__baofeng_skip"] = "暴风",
  ["$YS__gaotian1"] = "飞，比跑快吧?",
  ["$YS__gaotian2"] = "留意脚下。",
  ["$YS__gaotian3"] = "一起来玩吧。",
  ["$YS__gaotian4"] = "哟呼——",
  ["$YS__gaotian5"] = "在这哟。",
  ["$YS__baofeng1"] = "别想逃开喔?",
  ["$YS__baofeng2"] = "起风咯——",
  ["~YS__b_wd"] = "扑通。",
  ["$YS__b_wd_win_audio"] = "嘿嘿，要不要感谢「风神的眷顾」呀?",
}
YS__b_wd:addSkill(YS__gaotian)
YS__b_wd:addRelatedSkill(YS__baofeng)
YS__gaotian:addRelatedSkill(YS__baofeng_del)
YS__gaotian:addRelatedSkill(YS__baofengBuff)
YS__gaotian:addRelatedSkill(YS__baofeng_targetmod)
YS__gaotian:addRelatedSkill(YS__baofeng_skip)

local YS__mn = General(extension, "YS__mn", "Hydro", 3, 3, General.Female)
local YS__mnwin = fk.CreateActiveSkill{ name = "YS__mn_win_audio" }
YS__mnwin.package = extension
Fk:addSkill(YS__mnwin)
local YS__yinguo = fk.CreateTriggerSkill {
  name = "YS__yinguo",
  events = {fk.TurnStart},
  mute = true,
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, nil, "#askYG::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("YS__yinguo", math.random(1,2))
    room:notifySkillInvoked(player, "YS__yinguo", "special")
    room:setPlayerMark(target, "@@YS__yinguo-turn", 1)
  end,

  refresh_events = {fk.BeforeDrawCard},
  can_refresh = function(self, event, target, player, data)
    return target == player and target:getMark("@@YS__yinguo-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.fromPlace = "bottom"
  end,
}

local YS__yinguo_conjure = fk.CreateTriggerSkill{
  name = "#YS__yinguo_conjure",
  mute = true,
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("YS__yinguo", math.random(3,5))
    room:notifySkillInvoked(player, "YS__yinguo", "special")
      local Bcid = room:getNCards(4, "bottom")
      local Tcid = room:getNCards(4, "top")
      local to_ex = U.askForExchange(player, "Top", "Bottom", Tcid, Bcid, "#YS__yinguo-exchange", 4)
      local cards1, cards2 = {}, {}
      for _, id in ipairs(to_ex) do
        if table.contains(Tcid, id) then
        table.insert(cards2, id)
        end
      end
      for _, id in ipairs(to_ex) do
        if table.contains(Bcid, id) then
        table.insert(cards1, id)
        end
      end
      for _, id in ipairs(Tcid) do
        if not table.contains(cards2, id) then
        table.insert(cards1, id)
        end
      end
      for _, id in ipairs(Bcid) do
        if not table.contains(cards1, id) then
        table.insert(cards2, id)
        end
      end
      room:moveCards( 
        {
        ids = cards2,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
          drawPilePosition = -1,
        },
        {
        ids = cards1,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonJustMove,
          proposer = player.id,
          skillName = self.name,
          drawPilePosition = 1,
        }
      )
      room:askForGuanxing(player, room:getNCards(4, "top"), {4,4}, {0,0})
      room:askForGuanxing(player, room:getNCards(4, "bottom"), {0,0}, {4,4})
  end,
}

local YS__xvshi = fk.CreateViewAsSkill{
  name = "YS__xvshi",
  pattern = "jink,nullification,peach,slash,analeptic",
  anim_type = "special",
  mute = true,
  expand_pile = function() return Self:getTableMark("YS__xvshi") end,
  prompt = function()
    return "#YS__xvshi"
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 and table.contains(Self:getTableMark("YS__xvshi"), to_select) then
      local card = Fk:getCardById(to_select)
      if card.type == Card.TypeBasic or card.trueName == "nullification" then
        if Fk.currentResponsePattern == nil then
          return Self:canUse(card) and not Self:prohibitUse(card)
        else
          return Exppattern:Parse(Fk.currentResponsePattern):match(card)
        end
      end
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    return Fk:getCardById(cards[1])
  end,
  before_use = function(self, player, use)
    local room = player.room
    player:broadcastSkillInvoke("YS__yinguo", math.random(3,5))
    room:notifySkillInvoked(player, "YS__xvshi", "special")
    use.disresponsiveList = table.map(room.alive_players, Util.IdMapper)
  end,
  enabled_at_play = function(self, player)
    return false
  end,
  enabled_at_response = function(self, player, response)
    return player.phase == Player.NotActive
  end,
}
local YS__xvshi_trigger = fk.CreateTriggerSkill{
  name = "#YS__xvshi_trigger",
  mute = true,
  refresh_events = {fk.AskForCardUse, fk.AskForCardResponse, fk.BeforeCardUseEffect, fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    if event == fk.CardUsing then
      return player:hasSkill(self) and data.card.type == Card.TypeTrick
    else
      return target == player and player:hasSkill(self)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local n = 4
    local ids = {}
    for i = #room.draw_pile, #room.draw_pile - n + 1, -1 do
      if i < 1 then break end
      table.insert(ids, room.draw_pile[i])
    end
    player.room:setPlayerMark(player, "YS__xvshi", ids)
  end,
}
local YS__xinggui = fk.CreateActiveSkill{
  name = "YS__xinggui",
  anim_type = "control",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and table.find(Fk:currentRoom().alive_players, function(p) return p:getMark("@YS__xinggui") == 0 end)
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip and #selected == 0
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("@YS__xinggui") == 0
  end,
  target_num = 1,
  min_card_num = 1,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local player = room:getPlayerById(effect.from)
    local cards = effect.cards
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, self.name, nil, false)
    local suitsToRecord = table.map(cards, function(id)
      return Fk:getCardById(id):getSuitString(true)
    end)
    local suitsRecorded = type(target:getMark("@YS__xinggui")) == "table" and player:getMark("@YS__xinggui") or {}
    for _, suit in ipairs(suitsToRecord) do
      table.insertIfNeed(suitsRecorded, suit)
    end
    room:setPlayerMark(target, "@YS__xinggui", suitsRecorded)
  end,
}
local YS__xinggui_prohibit = fk.CreateProhibitSkill{
  name = "#YS__xinggui_prohibit",
  prohibit_use = function(self, player, card)
    return card and player:getMark("@YS__xinggui") ~= 0 and table.contains(player:getMark("@YS__xinggui"), "log_"..card:getSuitString())
  end,
}
local YS__xinggui_damaged = fk.CreateTriggerSkill{
  name = "#YS__xinggui_damaged",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    local to = data.to
    return to:getMark("@YS__xinggui") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local discards = table.filter(to:getCardIds({ Player.Hand, Player.Equip }), function(id)
      return table.contains(to:getMark("@YS__xinggui"), "log_"..Fk:getCardById(id):getSuitString()) and not to:prohibitDiscard(Fk:getCardById(id))
    end)
    local num = #discards
    local s = room:askForChoice(target, {"YS__xingguiqp", "jiashang"}, self.name, "#YS__xinggui-choice")
    if s == "YS__xingguiqp" then
      room:throwCard(discards, self.name, to, target)
    else
      data.damage = data.damage + num
    end
    room:setPlayerMark(to, "@YS__xinggui", 0)
  end,
}

YS__mn:addSkill(YS__yinguo)
YS__yinguo:addRelatedSkill(YS__yinguo_conjure)
YS__mn:addSkill(YS__xvshi)
YS__xvshi:addRelatedSkill(YS__xvshi_trigger)
YS__mn:addSkill(YS__xinggui)
YS__xinggui:addRelatedSkill(YS__xinggui_prohibit)
YS__xinggui:addRelatedSkill(YS__xinggui_damaged)
Fk:loadTranslationTable{
  ["YS__mn"] = "莫娜",
  ["YS__yinguo"] = "因果",
  ["#askYG"] = "因果:令%dest本回合从牌堆底摸牌",
  ["#YS__yinguo_conjure"] = "因果",
  [":YS__yinguo"] = "回合开始时，你观看牌堆顶4张牌和牌堆底4张牌并交换其中任意张牌，然后以任意顺序放回牌堆顶和牌堆底的牌。<br/>每轮限一次，其他角色的回合开始时，你可以令其本回合从牌堆底摸牌。"..
  "<br/><font color='grey'>#左边是牌堆顶，右边才是牌堆底！</font>",
  ["@@YS__yinguo-turn"] = "因果",
  ["#YS__yinguo-exchange"] = "因果",
  ["#YS__xvshi"] = "虚实",
  ["YS__xvshi"] = "虚实",
  [":YS__xvshi"] = "当你于回合外需要使用或打出一张基本牌或【无懈可击】时，你可以观看牌堆底的四张牌，若你观看的牌中有此牌，你可以使用或打出之。你以此法使用的【无懈可击】无法被响应。",
  ["YS__xinggui"] = "星异",
  [":YS__xinggui"] = "限定技，出牌阶段，你可以将一张手牌交给一名其他角色令其获得此牌花色的“星异”。<br/>其不能使用或打出与“星异”花色相同的牌；其受到伤害时，令伤害来源选择一项：1.弃置其所有与“星异”花色相同的牌；2.令本次伤害+X。如此做，其移除“星异”（X为其与“星异”花色相同的牌的数量）",
  ["YS__xingguiqp"] = "弃置所有与星异花色相同的牌",
  ["jiashang"] = "增加伤害",
  ["#YS__xinggui_damaged"] = "星异",
  ["@YS__xinggui"] = "星异",
  ["#YS__xinggui-choice"] = "星异",
  ["$YS__yinguo1"] = "此乃，命运。",
  ["$YS__yinguo2"] = "繁星，尽在掌握。",
  ["$YS__yinguo3"] = "命运，倒映水中。",
  ["$YS__yinguo4"] = "水中幻愿。",
  ["$YS__yinguo5"] = "…命运的虚影。",
  ["$YS__yinguo6"] = "水中之影，涟漪中窥见启明星升起。",
  ["$YS__yinguo7"] = "虚假之天，星空下的命运早已注定。",
  ["$YS__xinggui1"] = "命定于此。",
  ["$YS__xinggui2"] = "命运，在此显现。",
  ["$YS__xinggui3"] = "天命既定！",
  ["$YS__mn_win_audio"] = "命中当如此，我早已预知到了。",
  ["~YS__mn"] = "星空…黯淡…",
}

local YS__stjl = General(extension, "YS__stjl", "Hydro", 3, 3, General.Agender)
local YS__stjlwin = fk.CreateActiveSkill{ name = "YS__stjl_win_audio" }
YS__stjlwin.package = extension
Fk:addSkill(YS__stjlwin)
local YS__boren = fk.CreateTriggerSkill{
  name = "YS__boren",
  mute = true,
  anim_type = "offensive",
  events = {fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not player:isProhibited(p, data.card) then
        table.insertIfNeed(targets, p.id)
      end
    end
    if #targets == 0 then return end
    local to = {}
    to = room:askForChoosePlayers(player, targets, 1, 1, "#boren-invoke:::"..data.card:toLogString(), self.name, true)
    if #to > 0 then
      self.cost_data = to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local t = self.cost_data
    player:broadcastSkillInvoke(self.name, math.random(1,4))
    for i = 1, #t do
    TargetGroup:pushTargets(data.targetGroup, t[i])
    end
  end,
}
local YS__anliu = fk.CreateTriggerSkill{
  name = "YS__anliu",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash"
    else
      return target ~= player and player:hasSkill(self) and target:getMark("@@YS__anliu") ~= 0
    end
  end,
  on_cost = function(self, event, target, player, data)
      return true
    end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      local to = data.to
      if to ~= player then
        player.room:setPlayerMark(to, "@@YS__anliu", 1)
      end
    else
      player.room:setPlayerMark(target, "@@YS__anliu", 0)
    end
  end,
}
local YS__anliu_trig = fk.CreateInvaliditySkill {
  name = "#YS__anliu_trig",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@YS__anliu") ~= 0
    and not (skill:isEquipmentSkill() or skill.name:endsWith("&"))
  end
}
local doxinsheng = function (room, player)
  player:throwAllCards("ejh")
  room:handleAddLoseSkills(player, "YS__jiliu", nil)
  if player.dead then return end
  player:drawCards(4, "YS__xinshengW")
  if not player.dead then
    room:recover({
      who = player,
      num = 2 - player.hp,
      recoverBy = player,
      skillName = "YS__xinshengW",
    })
  end
  if not player.dead then
    player:reset()
  end
end
local YS__xinshengW = fk.CreateTriggerSkill{
  name = "YS__xinshengW",
  frequency = Skill.Limited,
  events = {fk.AskForPeaches},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.dying and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    room:notifySkillInvoked(player, self.name)
    doxinsheng (room, player)
    room:handleAddLoseSkills(player, "ol_ex__shensu", nil)
    if room.current ~= player then
      room:setPlayerMark(room.current, "@@YS__anliu", 1)
    end
  end,
}

YS__stjl:addSkill(YS__boren)
YS__stjl:addSkill(YS__anliu)
YS__anliu:addRelatedSkill(YS__anliu_trig)
YS__stjl:addSkill(YS__xinshengW)
YS__stjl:addRelatedSkill("ol_ex__shensu")
Fk:loadTranslationTable{
  ["YS__stjl"] = "深渊使徒",
  ["YS__boren"] = "波刃",
  [":YS__boren"] = "你使用【杀】可以额外增加一个目标（无距离限制且可重复）。",
  ["YS__anliu"] = "暗流",
  [":YS__anliu"] = "锁定技，当你使用【杀】对其他角色造成伤害后，你令其获得“暗流”，有“暗流”的角色所有技能失效直到其回合结束。",
  ["#boren-invoke"] = "波刃：你可以为此%arg增加一个目标（无距离限制且可重复）",
  ["#YS__anliu_trig"] = "暗流",
  ["@@YS__anliu"] = "<font color='#921AFF'>暗流</font>",
  ["YS__xinshengW"] = "新生",
  [":YS__xinshengW"] = "限定技，当你处于濒死状态时，你可以弃置区域内所有牌将体力值回复至2并复原武将牌，然后你摸四张牌;获得〖神速〗；令当前回合角色获得“暗流”。",
}

local YS__yjsw = General(extension, "YS__yjsw", "Normal", 2, 2, General.Agender)
YS__yjsw.shield = 4
local YS__jixie = fk.CreateFilterSkill{
  name = "YS__jixie",
  frequency = Skill.Compulsory,
  card_filter = function(self, to_select, player)
    return player:hasSkill(self) and (to_select.type == Card.TypeEquip or to_select.name == "peach" or to_select.name == "analeptic")and
    table.contains(player.player_cards[Player.Hand], to_select.id)
  end,
  view_as = function(self, to_select)
    local card = Fk:cloneCard("stab__slash", to_select.suit, to_select.number)
    card.skillName = self.name
    return card
  end,
}
local YS__jixie_targetmod = fk.CreateTargetModSkill{
  name = "#YS__jixie_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return player:hasSkill(YS__jixie) and skill.trueName == "slash_skill" and card and table.contains(card.skillNames, "YS__jixie")
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return player:hasSkill(YS__jixie) and skill.trueName == "slash_skill" and card and table.contains(card.skillNames, "YS__jixie")
  end,
}
local YS__jixie_trig = fk.CreateTriggerSkill{
  name = "#YS__jixie_trig",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    for _, move in ipairs(data) do
      if move.to == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.toArea ~= Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local i = 0
    for _, move in ipairs(data) do
      if move.to == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.toArea ~= Card.PlayerHand then
            i = i + 1
          end
        end
      end
    end
    self.cancel_cost = false
    for _ = 1, i do
      if self.cancel_cost or not player:hasSkill(self) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if room:getCardArea(id) ~= Card.PlayerHand and room:getCardOwner(id) == player then
            table.insert(cards, id)
          end
        end
      end
      if #cards == 0 then
        return false
      end
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
  end,
}
local YS__waijia = fk.CreateTriggerSkill{
  name = "YS__waijia",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.DamageInflicted, fk.Damaged, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self) and data.damageType == fk.NormalDamage and player.shield ~= 0
    elseif event == fk.Damaged then
      return target == player and player:hasSkill(self) and data.damageType == fk.NormalDamage and player.shield == 0 and player:getMark("YS__wj") == 0
    else
      return target == player and player:hasSkill(self) and player.shield == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    if event == fk.DamageInflicted then
      data.damage = math.max(1,math.floor(data.damage / 2))
    elseif event == fk.Damaged then
      player:broadcastSkillInvoke(self.name, 2)
      room:setPlayerMark(player, "YS__wj", 1)
      player:turnOver()
    else
      player:broadcastSkillInvoke(self.name, 1)
      room:setPlayerMark(player, "YS__wj", 0)
      room:changeShield(player, 4)
    end
  end,
}
local YS__waijia_maxcards = fk.CreateMaxCardsSkill{
  name = "#YS__waijia_maxcards",
  correct_func = function(self, player)
    return player:hasSkill(YS__waijia) and player.shield or 0
  end,
}
YS__yjsw:addSkill(YS__jixie)
YS__jixie:addRelatedSkill(YS__jixie_targetmod)
YS__jixie:addRelatedSkill(YS__jixie_trig)
YS__yjsw:addSkill(YS__waijia)
YS__waijia:addRelatedSkill(YS__waijia_maxcards)
Fk:loadTranslationTable{
  ["YS__yjsw"] = "遗迹守卫",
  ["YS__jixie"] = "践踏",
  [":YS__jixie"] = "锁定技，你的装备牌、【桃】和【酒】均视为无距离和次数限制的刺【杀】。当有牌进入你的判定区和装备区时，你获得之。",
  ["#YS__jixie_targetmod"] = "践踏",
  ["YS__waijia"] = "外甲",
  [":YS__waijia"] = "锁定技，当你受到伤害时，若你有护甲，则你受到的所有普通伤害减半（向下取整且至少为1）；当你失去所有护甲时，你翻面；回合开始时若你没有护甲，你获得4点护甲。你的手牌上限+X（X为你的护甲值）",
}

local YS__kl = General(extension, "YS__kl", "Pyro", 3, 3, General.Female)
local doLUCK = function (room, n)
  local X
    for i, id in ipairs(room.draw_pile) do
      if n == "Heart" and Fk:getCardById(id).suit == Card.Heart then
        X = id
        table.remove(room.draw_pile, i)
        break
      elseif n == "Spade" and Fk:getCardById(id).suit == Card.Spade then
        X = id
        table.remove(room.draw_pile, i)
        break
      elseif n == "Club" and Fk:getCardById(id).suit == Card.Club then
        X = id
        table.remove(room.draw_pile, i)
        break
      elseif n == "Diamond" and Fk:getCardById(id).suit == Card.Diamond then
        X = id
        table.remove(room.draw_pile, i)
        break
      elseif n == "NotHT" and Fk:getCardById(id).suit ~= Card.Spade then
        X = id
        table.remove(room.draw_pile, i)
        break
      end
    end
    if X then
      table.insert(room.draw_pile, 1, X)
    end
end
local YS__luck_buff = fk.CreateTriggerSkill{
  name = "YS__luck_buff",
  events = {fk.CardEffecting, fk.StartJudge},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffecting then
    return player:hasSkill(self) and target == player and (data.card.trueName == "indulgence" or data.card.trueName == "supply_shortage" or data.card.trueName == "binglinchengxia" or data.card.trueName == "jieziduanliang"
  or data.card.trueName == "xiuyangshengxi" or data.card.trueName == "timebomb" or data.card.trueName == "lucky_coin" or data.card.trueName == "lightning" or data.card.trueName == "wd_save_energy" or data.card.trueName == "paranoid"
  or data.card.trueName == "floating_thunder")
    else
      return player:hasSkill(self) and target == player and table.contains({"eight_diagram", "#eight_diagram_skill"}, data.reason)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
  local room = player.room
  if event == fk.CardEffecting then
    if data.card.trueName == "indulgence" then
      doLUCK(room, "Heart")
    elseif data.card.trueName == "supply_shortage" then
      doLUCK(room, "Club")
    elseif data.card.trueName == "binglinchengxia" then
      doLUCK(room, "Diamond")
    elseif data.card.trueName == "jieziduanliang" then
      local num
      for i, id in ipairs(room.draw_pile) do
        if Fk:getCardById(id).number == 1 or Fk:getCardById(id).number == 13 then
          num = id
          table.remove(room.draw_pile, i)
          break
        end
      end
      if num then
        table.insert(room.draw_pile, 1, num)
      end
    elseif data.card.trueName == "xiuyangshengxi" then
      local Red
      for i, id in ipairs(room.draw_pile) do
        if Fk:getCardById(id).color == Card.Red then
          Red = id
          table.remove(room.draw_pile, i)
          break
        end
      end
      if Red then
        table.insert(room.draw_pile, 1, Red)
      end
    elseif data.card.trueName == "timebomb" then
      doLUCK(room, "NotHT")
    elseif data.card.trueName == "lucky_coin" then
      doLUCK(room, "NotHT")
    elseif data.card.trueName == "lightning" then
      doLUCK(room, "NotHT")
    elseif data.card.trueName == "wd_save_energy" then
      local NotFK
      for i, id in ipairs(room.draw_pile) do
        if Fk:getCardById(id).suit ~= Card.Diamond then
          NotFK = id
          table.remove(room.draw_pile, i)
          break
        end
      end
      if NotFK then
        table.insert(room.draw_pile, 1, NotFK)
      end
    elseif data.card.trueName == "paranoid" then
      doLUCK(room, "Club")
    elseif data.card.trueName == "floating_thunder" then
      doLUCK(room, "NotHT")
    end
  else
    local Red
    for i, id in ipairs(room.draw_pile) do
      if Fk:getCardById(id).color == Card.Red then
        Red = id
        table.remove(room.draw_pile, i)
        break
      end
    end
    if Red then
      table.insert(room.draw_pile, 1, Red)
    end
  end
  end,
  priority = 3,
}
local YS__luck_draw = fk.CreateTriggerSkill{
  name = "#YS__luck_draw",
  events = {fk.BeforeDrawCard, fk.TurnStart},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
  local room = player.room
  if event == fk.BeforeDrawCard then
  local num = data.num
  local ids = {}
  if player.phase ~= player.NotActive then
    ids = room:getCardsFromPileByRule("ex_nihilo", num, "drawPile")
    if #ids == 0 then
      local cards = table.clone(player:getCardIds("h"))
      local n = 0
      local s = 0
      local b = 0
      for _, id in ipairs(cards) do
        if Fk:getCardById(id, true).name == "peach" then
          n = n + 1
        end
        if Fk:getCardById(id, true).trueName == "slash" then
          s = s + 1
        end
        if Fk:getCardById(id, true).trueName == "jink" then
          b = b + 1
        end
      end
      if player:isWounded() and n < player:getLostHp() then
        ids = room:getCardsFromPileByRule("peach", player:getLostHp())
      elseif b == 0 then
        table.insert(ids, room:getCardsFromPileByRule("jink", 1)[1])
      elseif s == 0 then
        table.insert(ids, room:getCardsFromPileByRule("slash", 1)[1])
      else
        ids = room:getCardsFromPileByRule("dismantlement,snatch,indulgence,savage_assault,archery_attack,duel,OCG__T_T_T,tuji", 1)
      end
      if s > 2 and not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).trueName == "crossbow" or Fk:getCardById(id).trueName == "sw_hhzn" end) and not table.find(room.alive_players, function(p) return  p == player and (p:getEquipment(Card.SubtypeWeapon) and (Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "crossbow" or Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "sw_hhzn")) end) then
        table.insert(ids, room:getCardsFromPileByRule("crossbow,sw_hhzn", 1)[1])
      end
      if table.find(room.alive_players, function(p) return  p == player and (p:getEquipment(Card.SubtypeWeapon) and (Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "crossbow" or Fk:getCardById(p:getEquipment(Card.SubtypeWeapon), true).name == "sw_hhzn")) end) then
        table.insert(ids, room:getCardsFromPileByRule("slash", 1)[1])
      end
      if not player:getEquipment(Card.SubtypeArmor) and not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeArmor end) then
        table.insert(ids, room:getCardsFromPileByRule("eight_diagram,nioh_shield,sw_llsmd", 1)[1])
      end
      if not player:getEquipment(Card.SubtypeDefensiveRide) and not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeDefensiveRide end) then
        table.insert(ids, room:getCardsFromPileByRule(".|.|.|.|.|defensive_ride", 1)[1])
      end
      if not player:getEquipment(Card.SubtypeTreasure) and not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeTreasure end) then
        table.insert(ids, room:getCardsFromPileByRule("hidding_sharp,wonder_map,sw_hlzjg", 1)[1])
      end
      if not player:getEquipment(Card.SubtypeWeapon) and not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeWeapon end) then
        table.insert(ids, room:getCardsFromPileByRule(".|.|.|.|.|weapon", 1)[1])
      end
      if not player:getEquipment(Card.SubtypeOffensiveRide) and not table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end) then
        table.insert(ids, room:getCardsFromPileByRule(".|.|.|.|.|offensive_ride", 1)[1])
      end
    end
  else
    ids = room:getCardsFromPileByRule("nullification,peach", num)
  end
    for _, id in ipairs(ids) do
      table.removeOne(room.draw_pile, id)
    end
    for _, id in ipairs(ids) do
      table.insert(room.draw_pile, 1, id)
    end
  else
    player:broadcastSkillInvoke("YS__luck_buff")
    for _, id in ipairs(room.discard_pile) do
      local b = 0
      if Fk:getCardById(id).name == "ex_nihilo" then
        table.removeOne(room.discard_pile, id)
        table.insert(room.draw_pile, math.random(#room.draw_pile), id)
        b = b + 1
      end
      if b == 2 then break end
    end
  end
  end,
  priority = 2,
}
YS__kl:addSkill(YS__luck_buff)
YS__luck_buff:addRelatedSkill(YS__luck_draw)
Fk:loadTranslationTable{
  ["YS__kl"] = "可莉",
  ["YS__luck_buff"] = "幸运",
  [":YS__luck_buff"] = "锁定技，摸牌或判定时概率获得“强运”。",
}

local YS__ky = General(extension, "YS__ky", "Cryo", 3, 3, General.Male)
local YS__kywin = fk.CreateActiveSkill{ name = "YS__ky_win_audio" }
YS__kywin.package = extension
Fk:addSkill(YS__kywin)
local YS__shuangxi = fk.CreateTriggerSkill{
  name = "YS__shuangxi",
  events = {fk.AfterCardsMove},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        local to = player.room:getPlayerById(move.to)
        if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand and not to.dead and to.phase == Player.NotActive and #to:getPile("YS__shuang") < 10 then
          data.shuangxi_moveto = move.to
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, nil, "#YS__shuangxi-invoked::" .. data.shuangxi_moveto)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
          local to = player.room:getPlayerById(move.to)
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == to then
              to:addToPile("YS__shuang", Fk:getCardById(id), true, self.name)
            end
          end
        end
      end
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and #player:getPile("YS__shuang") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local dummy = Fk:cloneCard("zixing")
    dummy:addSubcards(player:getPile("YS__shuang"))
    local room = player.room
    room:obtainCard(player.id, dummy, true)
  end,
}
local YS__linlun = fk.CreateViewAsSkill{
  name = "YS__linlun",
  anim_type = "offensive",
  card_num = 0,
  prompt = "#YS__linlun",
  card_filter = function(self, to_select, selected)
    return false
  end,
  view_as = function(self, cards)
    local card = Fk:cloneCard("duel")
    return card
  end,
  before_use = function(self, player, use)
    local targets = TargetGroup:getRealTargets(use.tos)
    if #targets == 0 then return end
    local room = player.room
    for _, p in ipairs(targets) do
      room:getPlayerById(p):drawCards(1)
    end
  end,
  after_use = function(self, player, use)
    local room = player.room
    if use.damageDealt then
      for _, p in ipairs(room.alive_players) do
        if use.damageDealt[p.id] then
          if p == player then
            player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
          else
            if #p:getPile("YS__shuang") > 0 then
              room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name,
              })
              local dummy = Fk:cloneCard("zixing")
              dummy:addSubcards(p:getPile("YS__shuang"))
              room:obtainCard(player.id, dummy, true)
            end
          end
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end
}
YS__ky:addSkill(YS__shuangxi)
YS__ky:addSkill(YS__linlun)
Fk:loadTranslationTable{
  ["YS__ky"] = "凯亚",
  ["YS__shuangxi"] = "霜袭",
  [":YS__shuangxi"] = "当有其他角色于其回合外获得牌时，你可以将这些牌置于其武将牌上称为“霜”（上限10），其回合开始时，获得武将牌上所有“霜”。",
  ["YS__shuang"] = "霜",
  ["YS__linlun"] = "凛轮",
  ["#YS__shuangxi-invoked"] = "霜袭：将%dest获得的牌置于其武将牌上",
  ["#YS__linlun"] = "对一名角色使用决斗，有概率获得牌。",
  [":YS__linlun"] = "出牌阶段限一次，你可以令一名其他角色摸一张牌并视为对其使用一张【决斗】，若此【决斗】对其造成伤害，则你回复一点体力并获得其所有“霜”；若你因此受到伤害，则你视为未使用过此技能。",
}

local YS__ls = General(extension, "YS__ls", "Electro", 3, 3, General.Female)
local YS__lswin = fk.CreateActiveSkill{ name = "YS__ls_win_audio" }
YS__lswin.package = extension
Fk:addSkill(YS__lswin)
local YS__canglei_active = fk.CreateActiveSkill{
  name = "YS__canglei_active",
  anim_type = "control",
  mute = true,
  prompt = "#YS__canglei_active",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:hasSkill(self.name) and not player:isNude()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("YS__canglei-phase") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cards = target:getCardIds("eh")
    room:throwCard(effect.cards, self.name, player, player)
    room:addPlayerMark(target, "YS__canglei-phase", 1)
    if target:getMark("@YS__yinlei") ~= 6 then
      player:broadcastSkillInvoke(self.name, math.random(1,3))
      room:addPlayerMark(target, "@YS__yinlei", 1)
      room:throwCard(table.random(cards,1), self.name, target, player)
    elseif target:getMark("@YS__yinlei") == 6 then
      room.logic:trigger("fk.leibao", target, { name = "@YS__yinlei", num = -1 })
    end
  end,
}
local YS__canglei = fk.CreateTriggerSkill{
  name = "#YS__canglei",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local cardnum = player:getHandcardNum()
    return cardnum%2 == 1 and target == player and player:hasSkill(self) and data.card.type ~= Card.TypeEquip and data.firstTarget and (not table.contains(AimGroup:getAllTargets(data.tos), player.id) or data.card.name == "amazing_grace" or data.card.name == "god_salvation" or data.card.name == "iron_chain")
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
    if #AimGroup:getAllTargets(data.tos) == 0 then return end
      for _, id in ipairs(AimGroup:getAllTargets(data.tos)) do
        local t = player.room:getPlayerById(id)
        if t ~= player and t:getMark("@YS__yinlei") ~= 6 then
          local cards = t:getCardIds("eh")
          player:broadcastSkillInvoke("YS__canglei_active", math.random(1,3))
          player.room:addPlayerMark(t, "@YS__yinlei", 1)
          room:throwCard(table.random(cards,1), "YS__canglei_active", t, player)
        elseif t ~= player and t:getMark("@YS__yinlei") == 6 then
          room.logic:trigger("fk.leibao", t, { name = "@YS__yinlei", num = -1 })
        end
      end
    end
  end,
}
local YS__leibao = fk.CreateTriggerSkill{
  name = "YS__leibao",
  anim_type = "offensive",
  events = {"fk.leibao"},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.name == "@YS__yinlei" and data.num < 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local src = table.find(room.alive_players, function(p) return p:hasSkill(self.name, true) end)
    if src then
    src:broadcastSkillInvoke("YS__canglei_active", math.random(4,6))
    room:damage{
      from = src,
      to = target,
      damage = 1,
      damageType = fk.ThunderDamage,
      skillName = self.name,
    }
    end
    room:addPlayerMark(target, "@YS__yinlei", -2)
  end,
}
local YS__maichong = fk.CreateActiveSkill{
  name = "YS__maichong",
  frequency = Skill.Limited,
  can_use = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 1,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select).deputyGeneral == ""
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if target.deputyGeneral == "" then
      room:changeHero(target, "YS__qwlg", false, true, true, false)
    end
  end,
}

YS__ls:addSkill(YS__canglei_active)
YS__canglei_active:addRelatedSkill(YS__canglei)
YS__ls:addSkill(YS__leibao)
YS__ls:addSkill(YS__maichong)
Fk:loadTranslationTable{
  ["YS__ls"] = "丽莎",
  ["YS__canglei_active"] = "苍雷",
  ["#YS__canglei_active"] = "令一名角色获得“引雷”，可能获得牌或造成伤害",
  [":YS__canglei_active"] = "出牌阶段每名角色限一次，你可以弃置一张黑色牌令一名其他角色获得一层“引雷”；当你使用牌指定其他角色为目标时，若你的手牌数为奇数，则你可以令所有目标获得一层“引雷”；每当一名角色的“引雷”增加时，你随机弃置其一张牌。（上限为6）。",
  ["#YS__canglei"] = "苍雷",
  ["@YS__yinlei"] = "<font color='#9F35FF'>引雷</font>",
  ["YS__leibao"] = "雷暴",
  [":YS__leibao"] = "锁定技,当一名角色的“引雷”达到上限后，其再获得“引雷”时，你对其造成一点雷电伤害并减少其2层“引雷”。",
  ["YS__maichong"] = "脉冲",
  [":YS__maichong"] = "限定技，出牌阶段，你可以选择一名没有副将的角色并在其副将处召唤“蔷薇雷光”。"..
  "<br/><font color='grey'>#\"<b>蔷薇雷光</b>\"：锁定技，结束阶段，令你攻击范围内所有除丽莎外的其他角色获得一层“引雷”；当你进入濒死状态时或三个回合后，移除你的副将。",
}

local YS__qwlg = General(extension, "YS__qwlg", "Electro", 0, 0, General.Agender)
YS__qwlg.total_hidden = true
local YS__leiguang = fk.CreateTriggerSkill {
  name = "YS__leiguang",
  anim_type = "offensive",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish
    else
      return target == player and player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local src = table.find(room.alive_players, function(p) return p:hasSkill("YS__canglei_active", true) end)
    if src then
      src:broadcastSkillInvoke("YS__maichong", math.random(1,3))
    end
    if event == fk.EventPhaseStart then
      for _, p in ipairs(room.alive_players) do
        if player:inMyAttackRange(p) and p.general ~= "YS__ls" then
          room:doIndicate(player.id, {p.id})
          if p:getMark("@YS__yinlei") ~= 6 then
            room:addPlayerMark(p, "@YS__yinlei", 1)
            if src then
            local cards = p:getCardIds("eh")
            room:throwCard(table.random(cards,1), "YS__canglei_active", p, src)
            end
          elseif p:getMark("@YS__yinlei") == 6 then
            room.logic:trigger("fk.leibao", p, { name = "@YS__yinlei", num = -1 })
          end
        end
      end
      room:addPlayerMark(player, "YS__qwlglife", 1)
      if player:getMark("YS__qwlglife") == 3 then
        if player.deputyGeneral ~= "" then
          local skills = {}
          local originalSkills = Fk.generals[player.deputyGeneral]:getSkillNameList()
          for _, skill in ipairs(originalSkills) do
            table.insert(skills, skill)
          end
          if #skills > 0 then
            room:handleAddLoseSkills(target, "-" .. table.concat(skills, "|-"), nil, true, false)
          end
          room:setPlayerProperty(player, "deputyGeneral", "")
        end
      end
    else
      if player.deputyGeneral ~= "" then
        local skills = {}
        local originalSkills = Fk.generals[player.deputyGeneral]:getSkillNameList()
        for _, skill in ipairs(originalSkills) do
          table.insert(skills, skill)
        end
        if #skills > 0 then
          room:handleAddLoseSkills(target, "-" .. table.concat(skills, "|-"), nil, true, false)
        end
        room:setPlayerProperty(player, "deputyGeneral", "")
      end
    end
  end,
}
YS__qwlg:addSkill(YS__leiguang)
Fk:loadTranslationTable{
  ["YS__qwlg"] = "蔷薇雷光",
  ["YS__leiguang"] = "雷光",
  [":YS__leiguang"] = "锁定技，结束阶段，令你攻击范围内所有除丽莎外的其他角色获得一层“引雷”；当你进入濒死状态时或三个回合后，移除你的副将。",
}

local YS__bbl = General(extension, "YS__bbl", "Hydro", 3, 3, General.Female)
local YS__bblwin = fk.CreateActiveSkill{ name = "YS__bbl_win_audio" }
YS__bblwin.package = extension
Fk:addSkill(YS__bblwin)
local YS__shanyao = fk.CreateTriggerSkill {
  name = "YS__shanyao",
  anim_type = "support",
  events = {fk.PreHpRecover},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and not target.dead then
      return event == fk.PreHpRecover and not data.shanyao and target.chained and data.recoverBy == player
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
        return p ~= target and p.chained
      end), function(p)
        return p.id
      end)
      if #availableTargets == 0 then return false end
      if #availableTargets >= 1 then
        for _, targetId in ipairs(availableTargets) do
          room:recover{
            who = room:getPlayerById(targetId),
            num = data.num,
            recoverBy = player,
            skillName = self.name,
            shanyao = true,
          }
        end
      end
  end,
}
local YS__qianchang = fk.CreateActiveSkill{
  name = "YS__qianchang",
  anim_type = "support",
  min_card_num = 1,
  min_target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return not Self:prohibitDiscard(Fk:getCardById(to_select)) and #selected < #Fk:currentRoom().alive_players
  end,
  target_filter = function(self, to_select, selected, cards)
    return #selected < #cards
  end,
  feasible = function (self, selected, selected_cards)
    return #selected > 0 and #selected == #selected_cards
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tos = effect.tos
    room:throwCard(effect.cards, self.name, player, player)
    room:sortPlayersByAction(tos)
    for _, pid in ipairs(tos) do
      local p = room:getPlayerById(pid)
      room:recover({
        who = p,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
      if not p.chained then
        p:setChainState(true)
      end
    end
  end,
}
local YS__anke = fk.CreateTriggerSkill{
  name = "YS__anke",
  events = {fk.PreHpRecover},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return data.num > target:getLostHp() and target:getMark("YS__anke-turn") == 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes(self.name, Player.HistoryPhase) == 1 then
      player:broadcastSkillInvoke(self.name, math.random(1,2))
    end
    room:setPlayerMark(target, "YS__anke-turn", 1)
    player:drawCards(1)
  end,
}
YS__bbl:addSkill(YS__shanyao)
YS__bbl:addSkill(YS__qianchang)
YS__bbl:addSkill(YS__anke)
Fk:loadTranslationTable{
  ["YS__bbl"] = "芭芭拉",
  ["YS__shanyao"] = "闪耀",
  [":YS__shanyao"] = "锁定技，当你不因此技能令一名处于横置状态的角色回复体力时，所有处于横置状态的其他角色回复等量体力。",
  ["YS__qianchang"] = "浅唱",
  [":YS__qianchang"] = "出牌阶段限一次，你可以弃置任意张牌，然后令等量角色回复一点体力并横置。",
  ["YS__anke"] = "安可",
  [":YS__anke"] = "每回合每名角色限一次，当有角色受到溢出回复时，你摸一张牌。",
}
return extension